<template>
	<view>
		<view class="state">
			<view :class="state==1?'s-title':'title'" @click="tab(1)">待使用</view>
			<view :class="state==2?'s-title':'title'" @click="tab(2)">已使用</view>
			<view :class="state==3?'s-title':'title'" @click="tab(3)">已失效</view>
		</view>
		<view class="box" v-for="(item,index) in list">
			<view class="detail">
				<view class="lcon">
					<view class="money"><text>￥</text>{{item.price}}</view>
					<view class="name">满{{item.limit}}减{{item.price}}</view>
				</view>
				<view class="rcon">
					<view class="title">{{item.name}}</view>
					<view class="time">到期：{{item.enddate}}</view>
				</view>
			</view>
			<view class="use" @click="use" v-if="state==1">立即使用</view>
			<view class="use" style="background-color: #eee;" v-if="state==2">已使用</view>
			<view class="use" style="background-color: #eee;" v-if="state==3">已失效</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				app: getApp().globalData,
				list: [],
				state: 1
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			tab(state) {
				this.state = state
				this.page = 1
				this.list = []
				this.getData()
			},
			getData() {
				this.app.post('/api/chef/user/coupon_list', {
					page: this.page,
					state: this.state
				}).then(res => {
					console.log(res)
					this.list = this.list.concat(res.data)
				})
			},
			use() {
				uni.switchTab({
					url: '/pages/lcIndex/lcIndex'
				})
			}
		},
		onReachBottom() {
			this.page += 1;
			this.getData();
		},
	}
</script>

<style lang="scss">
	.state {
		width: 750rpx;
		display: flex;
		justify-content: space-around;
		background-color: #FFFFFF;
	
		.s-title {
			// width: 120rpx; 
			line-height: 80rpx;
			border-bottom: 3px solid #84BD00;
			color: #84BD00;
			text-align: center;
			display: inline-block;
			margin-left: 20rpx;
			margin-right: 20rpx;
			font-size: 30rpx;
		}
	
		.title {
			// width: 120rpx;
			line-height: 80rpx;
			border-bottom: 2px solid #fff;
			display: inline-block;
			text-align: center;
			margin-left: 20rpx;
			margin-right: 20rpx;
			font-size: 30rpx;
		}
	}
	
	.box {
		width: 690rpx;
		height: 188rpx;
		border-radius: 16rpx;
		margin-left: 30rpx;
		margin-top: 30rpx;
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.detail {
			display: flex;
			align-items: center;

			.lcon {
				width: 210rpx;
				text-align: center;
				margin-top: -20rpx;

				.money {
					font-size: 52rpx;
					color: #84BD00;

					text {
						font-size: 30rpx;
					}
				}

				.name {
					font-size: 24rpx;
					color: #9E9E9E;
				}
			}

			.title {
				font-size: 30rpx;
				color: #333333;
			}

			.time {
				font-size: 24rpx;
				color: #999999;
				margin-top: 10rpx;
			}
		}

		.use {
			width: 140rpx;
			height: 60rpx;
			border-radius: 50rpx;
			background-color: #84BD00;
			font-size: 26rpx;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 30rpx;
		}
	}
</style>